package study8;

public class DynamicArray {
	private Object[] oaA=new Object[0];

	public void add(Object temp){
		Object[] oaB=new Object[oaA.length+1];
		oaB[oaA.length]=temp;
		for(int i=0;i<oaA.length;i++){
			oaB[i]=oaA[i];
		}
		oaA=oaB;
	}

	public int length(){
		return oaA.length;
	}
	public Object get(int index){
		return oaA[index];
	}
	public void remove(int index){
		Object[] oaB=new Object[oaA.length-1];
		int j=0;
		for(int i=0;i<oaA.length;i++){
			if(i!=index){
				oaB[j]=oaA[i];
				j++;
			}
		}
		oaA=oaB;
	}

	public void insert(Object obj,int index){
		Object[] oaB=new Object[oaA.length+1];
		int j=0;
		for(int i=0;i<oaA.length+1;i++){
			if(i!=index){
				oaB[i]=oaA[j];
				j++;
			}else{
				oaB[index]=obj;
			}
		}
		oaA=oaB;
	}
}
